import IScroll from 'iscroll';
import Vue from 'Vue'
const Common = {
    isLogin: () => {
        if (window.localStorage.getItem('userInfo') == null) {
            return false
        }
        return true
    },
    hasDeviceId: false,
    index2PageCount: (index, count) => Math.ceil(index / (count || 10)), // return lastIndex转总页数
    // iscroll点击兼容性问题
    iScrollClick: () => {
        if (/iPhone|iPad|iPod|Macintosh/i.test(navigator.userAgent)) return false;
        if (/Chrome/i.test(navigator.userAgent)) return (/Android/i.test(navigator.userAgent));
        if (/Silk/i.test(navigator.userAgent)) return false;
        if (/Android/i.test(navigator.userAgent)) {
            let s = navigator.userAgent.substr(navigator.userAgent.indexOf('Android') + 8, 3);
            if (parseFloat(s[0] + s[3]) < 44) {
                return false;
            } else {
                return true;
            }
        }
    },
    initScroll: (domStr) => {
        let iscroll = new IScroll(domStr, {
            preventDefault: false,
            click: Common.iScrollClick(),
            probeType: 3,
            scrollbars: true,
            fadeScrollbars: true,
            shrinkScrollbars: 'clip'
        });
    },
    stringTojson: (data) => {
        var odata = data.split(';');
        var allDate = [];
        for (var i = 0; i < odata.length; i++) {
            var oneDate = odata[i].split('_');
            allDate.push(oneDate);
        }
        return allDate;
    }
}
// 使用：Common.isLogin
module.exports = Common
// 使用Common.Common.isLogin
/* export default {
    // Common: Common缩写
    Common
} */